/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package goodenglish.interfaces;

import goodenglish.infrastructure.Config;
import goodenglish.interfaces.studyword.NewOrOldStudyPlanSelectDlg;
import goodenglish.interfaces.videoplay.MediaGroup;

import java.io.File;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.stage.FileChooser;

/**
 * 
 * @author 关攀攀 panpan_001@126.com
 */
public class MenuToolBar extends ToolBar {

	public MenuToolBar() {
		this.setMinWidth(Config.SCREEN_WIDTH);
		this.setMinHeight(Config.MENU_HEIGHT);
		/**
		 * 添加导入字幕单词菜单
		 */
		Button button1 = new Button("导入字幕");

		button1.getStyleClass().add("main-menu-item");
		button1.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				closeOldGroup();
				Main.root.setCenter(new SubtImportPane());
			}
		});
		this.getItems().add(button1);
		/**
		 * 添加导入字幕单词菜单
		 */
		Button newWordSettingBtn = new Button("设置词库生词");

		newWordSettingBtn.getStyleClass().add("main-menu-item");
		newWordSettingBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				closeOldGroup();
				Main.root.setCenter(new NewWordSetPane());
			}
		});
		this.getItems().add(newWordSettingBtn);
		/**
		 * 添加设置字幕词意菜单
		 */
		Button NewWordExplainSettingBtn = new Button("设置词意");
		NewWordExplainSettingBtn.getStyleClass().add("main-menu-item");
		NewWordExplainSettingBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				closeOldGroup();
				Main.root.setCenter(new NewWordExplainSetPane());
			}
		});
		this.getItems().add(NewWordExplainSettingBtn);
		/**
		 * 添加浏览背单词菜单
		 */
		Button button5 = new Button("背诵字幕单词");
		button5.getStyleClass().add("main-menu-item");
		button5.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				closeOldGroup();
				Main.instance.showModalMessage(new NewOrOldStudyPlanSelectDlg());

			}
		});
		this.getItems().add(button5);
		/**
		 * 添加浏览背单词菜单
		 */
		Button mediaBtn = new Button("看视频");
		mediaBtn.getStyleClass().add("main-menu-item");
		mediaBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {

				String filePath;
				FileChooser fileChooser = new FileChooser();
				File file = fileChooser.showOpenDialog(null);
				if (null != file) {
					filePath = file.getAbsolutePath();
					closeOldGroup();
					Main.root.setCenter(new MediaGroup(filePath));
				}

			}
		});
		this.getItems().add(mediaBtn);
		/**
		 * 添加程序设置菜单
		 */
		Button dataExportBtn = new Button("数据导出及备份");
		dataExportBtn.getStyleClass().add("main-menu-item");
		dataExportBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				closeOldGroup();
				Main.root.setCenter(new ExportPane());
			}
		});
		this.getItems().add(dataExportBtn);
		/**
		 * 添加程序设置菜单
		 */
		Button SettingBtn = new Button("程序设置");
		SettingBtn.getStyleClass().add("main-menu-item");
		SettingBtn.setOnAction(new EventHandler<ActionEvent>() {

			public void handle(ActionEvent event) {
				closeOldGroup();
				Main.root.setCenter(new SettingPane());
			}
		});
		this.getItems().add(SettingBtn);

	}

	public void closeOldGroup() {
		MediaGroup.close();

	}
}
